#include "roulette.h"
#include <ctime>
#include <cstdlib>
#include <iostream>

using namespace std;

Roulette::Roulette()
: ARRAY_SIZE(37), numberOfRotations(0), rotation(new int[ARRAY_SIZE]){}

Roulette::~Roulette(){
	delete [] rotation;
	cout << "Number of Rotations: " << numberOfRotations << endl;
}

int Roulette::playOneGame(){
	//srand((unsigned)time(NULL));		//richtige RandomZahlen 
	int x = rand() % ARRAY_SIZE;
	return x;
}

void Roulette::playRotation(){
	for (int i = 0; i < ARRAY_SIZE; i++)
		rotation[i] = playOneGame();
	numberOfRotations++;
}

const void Roulette::printRotation(){
	cout << "Rotations Nummer " << numberOfRotations << endl;
	cout << "Gezogene Zahlen:";
	for (int i = 0; i < ARRAY_SIZE; i++)
		cout << " " << rotation[i];
	cout << endl;
}

void Roulette::sortRotation(){
	for (int i = 0; i < ARRAY_SIZE - 1; i++) {
		int k = i;		//Index des kleinsten Elements
		int min = rotation[i];	//kleinstes Element

		for (int j = i + 1; j < ARRAY_SIZE; j++) {		//suche kleinstes Element
			if (rotation[j] < min) {
				k = j;
				min = rotation[j];
			}
		}
		rotation[k] = rotation[i];		//vertausche aktuelles Element mit kleinstem Element
		rotation[i] = min;
	}
}

const int Roulette::differentInRotation(){
	// ARRAY muss vorher sortiert sein!
	int differentNumbers = 1;
	int number = rotation[0];			// erste Zahl im Array wird zum vergleichen benutzt
	for (int i = 1; i < ARRAY_SIZE; i++) {
		if (rotation[i] != number) {
			differentNumbers++;
			number = rotation[i];
		}
	}
	return differentNumbers;
}

const long Roulette::getNumberOfRotations() {
	return numberOfRotations;
}